<html>
<div id="myheader">
<?php
        include "include/top.php";
error_reporting(E_ALL);
?>
</div>


<title>OSPMS</title>
<head>

<style type="text/css" media="all">
</style>
    <link rel="stylesheet" href="style/ospms-body.css" type="text/css">

<?php
  include "include/left-menu.php";
?>

<script type="text/javascript">
<!--
 function ExChgClsName(Obj,NameA,NameB){
  var Obj=document.getElementById(Obj)?document.getElementById(Obj):Obj;
  Obj.className=Obj.className==NameA?NameB:NameA;
 }
 function showMenu(iNo){
 ExChgClsName("Menu_"+iNo,"MenuBox","MenuBox2");
 }
-->
</script>
</head>

<body>
<div id="mymajorbody">
<div id="mybody">

<?php

echo "<table style='border: solid 1px black;'>";
$servername = "localhost";
$username = "ospms";
$password = "ospms";
$dbname = "OSPMS";

class TableRows extends RecursiveIteratorIterator {
    function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }
    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }
    function beginChildren() {
        echo "<tr>";
    }
    function endChildren() {
        echo "</tr>" . "\n";
    }
}
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$select = $conn->query('SELECT * FROM user');
$total_column = $select->columnCount();

for ($counter = 0; $counter <= $total_column; $counter ++) {
    $meta = $select->getColumnMeta($counter);
    $column[] = $meta['name'];
}

$stmt = $conn->prepare("DESCRIBE user");
$stmt->execute();
$table_fields = $stmt->fetchAll(PDO::FETCH_COLUMN);

	echo "<tr>". " \n";
for ( $i=0 ; $i<count($table_fields); $i++ ) {
	echo "<td>" ;
	print_r($table_fields[$i]);
	echo "</td>" ;
}
	echo "</tr>". " \n";

    $stmt = $conn->prepare("SELECT * FROM user");
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
        echo $v;
    }
    $dsn = null;
    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
$conn = null;
echo "</table>";
?> 
</div>
</div>

<div id="myfooter">
<?php
        include "include/bottom.php"
?>
</div>
